<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex align-center benben-position-layout flex search_flex_0"
        :style="{height:(100+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex align-center justify-between flex-sub search_fd0_0'>
          <text class='fu-iconfont2  search_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">&#xE794;</text>
          <view class='flex align-center flex-sub search_fd0_0_c1'>
            <image class='search_fd0_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"61.png"'></image>
            <benben-input class='flex-sub search_fd0_0_c1_c1' type="text" :focus='true' :placeholder="`搜索`"
              confirm-type="done" :maxlength="-1" placeholder-style="color:#999;font-size:28rpx"
              @confirm="addHistoricalFunc()" v-model="keyword" />
          </view>
        </view>

      </view>
      <view :style="{height: (100+StatusBarRpx)+'rpx'}"></view>
      <!---搜索记录flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout search_flex_1">
        <view class='flex flex-wrap align-center search_fd1_0'>
          <text class='search_fd1_0_c0'>历史搜索</text>
          <image class='search_fd1_0_c1' mode="aspectFit" :src='STATIC_URL+"41.png"'
            @tap.stop="popupShow1661481796822=true"></image>
        </view>
        <view class='flex flex-wrap align-center search_fd1_1'>
          <template v-for='(item,key0) in appSearchHistory'>
            <view class='flex align-center search_fd1_1_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
              :data-url="`/pages/shouye/searchResult/searchResult?keyworld=${item.name}`" :key='key0'>
              <text class='search_fd1_1_c0_c0'>{{item.name}}</text>
            </view>
          </template>

        </view>
        <text class='search_fd1_2' v-if=" appSearchHistory.length<'1'">暂无历史记录</text>
      </view>

      <!---搜索记录flex布局结束-->
      <benben-popup v-model="popupShow1661481796822" :mask="true" :mask-close-able="true" mode='center'>
        <!---删除历史记录弹窗flex布局开始-->
        <view class="flex flex-direction flex-wrap align-center search_flex_2">
          <text class='search_fd2_0'>确定删除历史记录？</text>
          <view class='flex flex-wrap align-center search_fd2_1'>
            <button class='search_fd2_1_c0' @tap.stop="popupShow1661481796822=false">取消</button>
            <button class='search_fd2_1_c1' @tap.stop="clearSearchFunc()">确定</button>
          </view>
        </view>

        <!---删除历史记录弹窗flex布局结束-->

      </benben-popup>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction align-stretch benben-flex-layout">
        <view class='flex flex-wrap align-center search_fd3_0'>
          <text class='search_fd3_0_c0'>搜索发现</text>
          <text class='search_fd3_0_c1' @tap.stop="getDiscoveryFunc()">换一批</text>
        </view>
        <view class='flex flex-wrap align-center search_fd3_1'>
          <template v-for='(item,key0) in discoveryList'>
            <view class='flex flex-wrap align-center search_fd3_1_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
              :data-url="`/pages/shouye/searchResult/searchResult?keyworld=${item.works}`" v-if=" key0==0" :key='key0'>
              <image class='search_fd3_1_c0_c0' mode="aspectFit" :src='STATIC_URL+"62.png"'></image>
              <text class='search_fd3_1_c0_c1'>{{item.works}}</text>
              <image class='search_fd3_1_c0_c2' mode="aspectFit" :src='STATIC_URL+"113.png"'></image>
            </view>
          </template>

          <template v-for='(item,key0) in discoveryList'>
            <view class='flex flex-wrap align-center search_fd3_1_c1' @tap.stop="handleJumpDiy" data-type="navigateTo"
              :data-url="`/pages/shouye/searchResult/searchResult?keyworld=${item.works}`" v-if=" key0!=0" :key='key0'>
              <text class='search_fd3_1_c1_c0'>{{item.works}}</text>
            </view>
          </template>

        </view>
      </view>
      <view class="flex flex-direction align-stretch benben-flex-layout">
        <view class='flex flex-wrap align-center search_fd3_0'>
          <text class='search_fd3_0_c0'>热门推荐</text>

        </view>
        <view class='flex flex-direction search_fd3_1'>
          <view class='flex text-cut search_fd3_1_c0_S' v-for='(item,key0) in dataList' @tap.stop="handleJumpDiy"
            data-type="navigateTo" :data-url="`/pages/shouye/postquestionsDetails/postquestionsDetails?id=${item.aid}`"
            v-if=" key0<10" :key='key0'>
            {{key0+1}}. {{item.title}}
          </view>

        </view>
      </view>
      <!---flex布局flex布局结束-->


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'

  export default {
    components: {},


    data() {
      return {
        "popupShow1661481796822": false,
        "keyword": "",
        "searchList": [],
        "discoveryList": [],
        "aid": "",
        dataList: []
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      appSearchHistory() { // 搜索历史
        return this.$store.state.appSearchHistory
      }
    },
    watch: {},
    onLoad(options) {
      this.getList()
      this.getHistoryFunc()
      this.getDiscoveryFunc()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {
      this.getHistoryFunc()
      this.getDiscoveryFunc()
    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //获取搜索历史
      async getHistoryFunc() {
        //请求方法
        //数据验证

        let datasearchList = await this.$api.get(global.apiUrls.post6579217dc9502, {

        });

        if (datasearchList.data.code != 1) {
          this.$message.info(datasearchList.data.msg);
          return
        }
        let infosearchList = datasearchList.data.data;
        this.searchList = infosearchList.data

      },
      async getList() {
        //请求方法
        //数据验证

        let datasearchList = await this.$api.get(global.apiUrls.post6576d52e059d0, {
          postcate_id: -1
        });

        if (datasearchList.data.code != 1) {
          this.$message.info(datasearchList.data.msg);
          return
        }
        let infosearchList = datasearchList.data.data;
        this.dataList = infosearchList.data
        console.log('dataList', this.dataList.length)

      },
      //获取搜索发现
      async getDiscoveryFunc() {
        //请求方法
        //数据验证

        let datadiscoveryList = await this.$api.get(global.apiUrls.post657922adb879c, {

        });

        if (datadiscoveryList.data.code != 1) {
          this.$message.info(datadiscoveryList.data.msg);
          return
        }
        let infodiscoveryList = datadiscoveryList.data;
        this.discoveryList = infodiscoveryList.data

      },
      //添加历史搜索
      addHistoricalFunc() {
        this.$store.commit('appSearchHistoryAdd', {
          "name": this.keyword
        })
        this.$urouter.navigateTo(`/pages/shouye/searchResult/searchResult?keyworld=${this.keyword}`);
      },
      //清空搜索历史
      clearSearchFunc() {
        this.$store.commit('appSearchHistoryClean', '')
        this.popupShow1661481796822 = false;
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #fff;
    background-size: 100% auto;
  }

  .search_flex_0 {
    background: #fff;
    width: 750rpx;
    height: 100rpx;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .search_fd0_0_c1_c1 {
    margin: 0rpx 0rpx 0rpx 16rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #333;
  }

  .search_fd0_0_c1_c0 {
    width: 24rpx;
    height: 24rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .search_fd0_0_c1 {
    background: rgba(249, 249, 249, 1);
    background-size: 100% auto !important;
    border-radius: 34rpx 34rpx 34rpx 34rpx;
    margin: 0rpx 0rpx 0rpx 24rpx;
    padding: 0rpx 24rpx 0rpx 24rpx;
    height: 64rpx;
  }

  .search_fd0_0_c0 {
    font-size: 36rpx;
    color: #333;
    font-weight: 500;
  }

  .search_fd0_0 {
    margin: 17rpx 32rpx 24rpx 32rpx;
  }

  .search_flex_1 {
    padding: 0rpx 0rpx 0rpx 0rpx;
  }

  .search_fd1_2 {
    font-size: 24rpx;
    font-weight: 400;
    color: #666666;
    margin: 0rpx 0rpx 32rpx 24rpx;
  }

  .search_fd1_1_c0_c0 {
    font-size: 24rpx;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
    margin: 0rpx 16rpx 0rpx 0rpx;
  }

  .search_fd1_1_c0 {
    background: rgba(248, 248, 248, 1);
    border-radius: 32rpx 32rpx 32rpx 32rpx;
    background-size: 100% auto !important;
    padding: 10rpx 22rpx 10rpx 22rpx;
    line-height: 24rpx;
    margin: 0rpx 12rpx 24rpx 12rpx;
  }

  .search_fd1_1 {
    padding: 0rpx 0rpx 0rpx 12rpx;
  }

  .search_fd1_0_c1 {
    width: 24rpx;
    height: 28rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .search_fd1_0_c0 {
    font-size: 32rpx;
    font-weight: 500;
    color: rgba(51, 51, 51, 1);
  }

  .search_fd1_0 {
    padding: 32rpx 0rpx 24rpx 0rpx;
    margin: 0rpx 24rpx 0rpx 24rpx;
  }

  .search_flex_2 {
    background: #fff;
    margin: 0rpx 105rpx 0rpx 105rpx;
    background-size: #eee;
    border-radius: 25rpx 25rpx 25rpx 25rpx;
    padding: 40rpx 0rpx 0rpx 0rpx;
  }

  .search_fd2_1_c1 {
    background: transparent;
    line-height: 110rpx;
    border-radius: 0rpx 0rpx 16rpx 0rpx;
    font-size: 32rpx;
    color: rgba(100, 80, 235, 1);
    width: 269rpx;
    height: 110rpx;
  }

  .search_fd2_1_c0 {
    border-right: 1px solid #EEEEEE;
    background: transparent;
    line-height: 110rpx;
    border-radius: 0rpx 0rpx 0rpx 16rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor2);
    height: 110rpx;
    width: 270rpx;
  }

  .search_fd2_1 {
    border-top: 1px solid #eee;
  }

  .search_fd2_0 {
    font-size: 32rpx;
    font-weight: 400;
    line-height: 52rpx;
    color: #333333;
    margin: 40rpx 0rpx 39rpx 0rpx;
  }

  .search_fd3_1_c1_c0 {
    font-size: 24rpx;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
  }

  .search_fd3_1_c1 {
    background: rgba(248, 248, 248, 1);
    border-radius: 32rpx 32rpx 32rpx 32rpx;
    background-size: 100% auto !important;
    padding: 10rpx 22rpx 10rpx 22rpx;
    line-height: 24rpx;
    margin: 0rpx 12rpx 24rpx 12rpx;
  }

  .search_fd3_1_c0_c2 {
    width: 18rpx;
    height: 32rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    position: absolute;
    top: -8rpx;
    right: 4rpx;
  }

  .search_fd3_1_c0_c1 {
    font-size: 24rpx;
    font-weight: 400;
    color: rgba(226, 47, 47, 1);
  }

  .search_fd3_1_c0_c0 {
    width: 18rpx;
    height: 32rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    position: absolute;
    top: -10rpx;
    right: 10rpx;
  }

  .search_fd3_1_c0 {
    border: 1px solid rgba(226, 47, 47, 1);
    background: rgba(248, 248, 248, 1);
    border-radius: 32rpx 32rpx 32rpx 32rpx;
    background-size: 100% auto !important;
    padding: 0rpx 40rpx 0rpx 40rpx;
    line-height: 56rpx;
    margin: 0rpx 12rpx 24rpx 12rpx;
    position: relative;
  }

  .search_fd3_1_c0_S {
    // padding: 0rpx 40rpx 0rpx 0;
    line-height: 100rpx;
    border-bottom: 2rpx solid #EEEEEE;
    margin: 0rpx 12rpx 0 12rpx;
    width: 702rpx;
  }

  .search_fd3_1 {
    padding: 0rpx 0rpx 0rpx 12rpx;
  }

  .search_fd3_0_c1 {
    border: 1px solid rgba(191, 191, 191, 1);
    margin: 0rpx 0rpx 0rpx auto;
    padding: 8rpx 16rpx 8rpx 16rpx;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    color: #333333;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 33rpx;
  }

  .search_fd3_0_c0 {
    font-size: 32rpx;
    font-weight: 700;
    color: rgba(51, 51, 51, 1);
  }

  .search_fd3_0 {
    padding: 32rpx 0rpx 15rpx 0rpx;
    margin: 0rpx 24rpx 0rpx 24rpx;
  }
</style>
